<table id="dg" title="数据列表" style="width:550px;height:250px">
</table>

<div id="toolbar">
    <div style="font-size:1.0em">
    <label style="margin-left:10px"> 日期：</label>
    <input id="date" type="text" value="2016-11-02" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser" />
        <script type="text/javascript">
 function myformatter(date){
 var y = date.getFullYear();
 var m = date.getMonth()+1;
 var d = date.getDate();
 return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
 function myparser(s){
 if (!s) return new Date();
 var ss = (s.split('-'));
var y = parseInt(ss[0],10);
 var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
}else{
 return new Date();
 }
 }
 </script>
    <a href="#" style="margin-left:10px;width:60px" class="easyui-linkbutton" onclick="getabout()">查询</a>

        <label style="margin-left:10px"> ASIN：</label>
        <input type="text" id="asin" name="asin" />
        <a href="#" class="easyui-linkbutton" onclick="getabout1()">ASIN查找</a>
        <a href="#" class="easyui-linkbutton" onclick="exportdata()">ASIN导出</a>
    </div>
</div>

<script type="text/javascript">
    $('#dg').datagrid({
        url: '/back/keep/query',
        collapsible: true,
        toolbar: '#toolbar',
        rownumbers: true,
        pageSize:20,
        pagination: true,
        pageList: [10, 20,50],
        fit: true,
        columns: [[
            {field: 'id', title: 'ID', width: 80, hidden: true},
             {field: 'asin', title: 'ASIN', width: 80, align: 'center'},
             {field: 'stock', title: '库存', width: 80, align: 'center'},
             {field: 'createtime', title: 'Createtime', width: 150, align: 'center'}
        ]]
    });


    function getabout() {
        var datename = $('#date').datebox('getValue');
        if(datename==""){
                       $.messager.show({	// show error message
                title: '消息',
                msg: "日期不能为空(20161010)"
            });
            return
        }

        $('#dg').datagrid('load', {
            datename: datename,
        });
    }


  function getabout1() {
        var asin = $('#asin').val();
        //alert(asin)
                if(asin==""){
          $.messager.show({	// show error message
                title: '消息',
                msg: "Asin不能为空"
            });
        return
        }
        $('#dg').datagrid('load', {
            asin:asin
        });

    }

       function exportdata() {
         var asin = $('#asin').val();
        //alert(asin)
                if(asin==""){
          $.messager.show({	// show error message
                title: '消息',
                msg: "Asin不能为空"
            });
        return
        }
        $.post('/back/keep/export', {'asin':asin}, function (result) {
                if(result.status==true){
                    window.open(result.info)
                }else{
                $.messager.show({	// show error message
                title: '消息',
                msg: result.info
            });
                }
           })
    }

</script>
